import cv2
import numpy as np

img = np.zeros((400, 600, 3), dtype=np.uint8) + 255
font = cv2.FONT_HERSHEY_PLAIN
points = []

def draw(event, x, y, flag, param):
    global points
    if event == cv2.EVENT_LBUTTONDBLCLK:
        xy = f"({x},{y})"
        cv2.putText(img, xy, (x, y), font, 2, (255, 0, 0))
        points.append([x, y])
        cv2.circle(img, (x, y), 5, (0, 255, 0), -1)
    elif event == cv2.EVENT_RBUTTONDOWN:
        pts = np.array([points], dtype=np.int32)
        cv2.polylines(img, [pts], True, (0, 0, 255))
        points = []
        cv2.imshow("test", img)
cv2.namedWindow("test")
cv2.setMouseCallback("test", draw)
cv2.imshow("test", img)
key = cv2.waitKey(100000)
if key == 27:
    cv2.destroyAllWindows()